#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <unordered_map>
#include <algorithm>
#include <cstdio>
#include <cstdlib>

using namespace std;

// 原始结构体定义
struct people {
    char id[19];     // 身份证号（18位+1个空字符）
    int social;       // 社保缴纳月数
    int area;         // 自有住房面积
    char date[11];    // 申报日期 MM-DD-YYYY（10位+1个空字符）
};

// 扩展结构体，用于排序和处理
struct Applicant {
    string id_str;
    int social_months;
    int own_area;
    string apply_date;
    int timestamp;
    bool is_eligible;
    int priority_group; // 0: 刚性需求 | 1: 改善需求
    int sort_key;       // 社保月数或面积
};

/**
 * 从 house.bin 文件中读取申请人数据
 * @param n 输出参数，返回报名总人数
 * @return 指向 people 数组的指针
 */
people* getMess(int &n) {
    FILE *fp = fopen("house.bin", "rb");
    if (!fp) {
        cerr << "无法打开文件 house.bin" << endl;
        exit(1);
    }

    // 获取文件长度
    fseek(fp, 0, SEEK_END);
    long fileSize = ftell(fp);
    rewind(fp); // 回到文件开头

    // 计算报名人数 n
    n = (fileSize - sizeof(int)) / sizeof(people);

    // 分配内存并读取数据
    people *tmp = new people[n];
    fread(tmp, sizeof(people), n, fp);

    // 读取最后的 n 值进行验证
    int nCheck;
    fread(&nCheck, sizeof(int), 1, fp);
    if (nCheck != n) {
        cerr << "文件结构错误或数据损坏" << endl;
        delete[] tmp;
        fclose(fp);
        exit(1);
    }

    fclose(fp);
    return tmp;
}

// 将日期字符串转为时间戳（简单用字符串比较即可）
int parseDate(const string& dateStr) {
    string noDash = dateStr;
    replace(noDash.begin(), noDash.end(), '-', ' ');
    int month, day, year;
    sscanf(noDash.c_str(), "%d %d %d", &month, &day, &year);
    return year * 365 + month * 30 + day; // 简化版时间戳
}

// 比较函数：用于排序
bool compareApplicants(const Applicant& a, const Applicant& b) {
    if (a.priority_group != b.priority_group)
        return a.priority_group < b.priority_group;

    if (a.sort_key != b.sort_key)
        return (a.priority_group == 0) ? a.sort_key > b.sort_key : a.sort_key < b.sort_key;

    return a.timestamp < b.timestamp;
}

int main() {
	  ios::sync_with_stdio(false);
  cin.tie(0);cout.tie(0);

    int m, T;
    cin >> m >> T;

    vector<string> queries(T);
    for (int i = 0; i < T; ++i) {
        cin >> queries[i];
    }

    int n;
    people* person = getMess(n); // 从 house.bin 获取数据

    vector<Applicant> applicants;

    for (int i = 0; i < n; ++i) {
        Applicant app;
        app.id_str = string(person[i].id, 18);
        app.social_months = person[i].social;
        app.own_area = person[i].area;

        // 判断是否符合条件
        app.is_eligible = (app.own_area == 0 && app.social_months >= 24);

        // 设置优先级组
        app.priority_group = app.is_eligible ? 0 : 1;

        // 申报时间解析
        app.apply_date = string(person[i].date, 10);
        app.timestamp = parseDate(app.apply_date);

        // 设置排序依据
        if (app.priority_group == 0) {
            app.sort_key = app.social_months;
        } else {
            app.sort_key = app.own_area;
        }

        applicants.push_back(app);
    }

    delete[] person;

    // 排序
    sort(applicants.begin(), applicants.end(), compareApplicants);

    // 构建身份证到排名的映射
    unordered_map<string, int> rankMap;

    for (int i = 0; i < (int)applicants.size();) {
        int j = i;
        while (j < (int)applicants.size() &&
               applicants[i].priority_group == applicants[j].priority_group &&
               applicants[i].sort_key == applicants[j].sort_key &&
               applicants[i].timestamp == applicants[j].timestamp) {
            ++j;
        }

        for (int k = i; k < j; ++k) {
            rankMap[applicants[k].id_str] = i + 1; // 名次从1开始
        }

        i = j;
    }

    // 处理查询
    for (const string& query : queries) {
        auto it = rankMap.find(query);
        if (it == rankMap.end()) {
            cout << "Sorry" << endl;
            continue;
        }

        int rank = it->second;

        if (rank > m) {
            cout << "Sorry" << endl;
            continue;
        }

        // 查找当前名次有多少人
        int same_rank_count = 0;
        for (int i = 0; i < (int)applicants.size(); ++i) {
            if (rankMap[applicants[i].id_str] == rank) {
                ++same_rank_count;
            }
        }

        if (same_rank_count == 1) {
            cout << rank << endl;
        } else if (m - rank + 1 >= same_rank_count) {
            cout << rank << " " << rank + same_rank_count - 1 << endl;
        } else {
            cout << m - rank + 1 << "/" << same_rank_count << endl;
        }
    }

    return 0;
}